﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Xuanxiang.Repository.Interface
{
    public interface I_Repository<T> where T : class,new()
    {
        /// <summary>
        /// 单个新增
        /// </summary>
        /// <param name="t"></param>
        void Add(T t);

        /// <summary>
        /// 批量新增
        /// </summary>
        /// <param name="ie"></param>
        void AddRange(IEnumerable<T> ie);


        /// <summary>
        /// 单个修改
        /// </summary>
        /// <param name="t"></param>
        void Update(T t);

        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="ie"></param>
        void UpdateRange(IEnumerable<T> ie);

        /// <summary>
        /// 单个删除
        /// </summary>
        /// <param name="t"></param>
        void Delete(T t);

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ie"></param>
        void DeleteRange(IEnumerable<T> ie);

        /// <summary>
        /// 保存
        /// </summary>
        /// <returns></returns>
        int SaveChanges();

        /// <summary>
        /// 保存
        /// </summary>
        /// <returns></returns>
        Task<int> SaveChangesAsync();

        /// <summary>
        /// 条件查询
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        IQueryable<T> GetAll(Expression<Func<T,bool>>? where=null);

        /// <summary>
        /// 排序查询
        /// </summary>
        /// <typeparam name="type"></typeparam>
        /// <param name="isAsc"></param>
        /// <param name="order"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        IQueryable<T> GetAll<type>(bool isAsc,Expression<Func<T,type>>? order=null,Expression<Func<T, bool>>? where = null);

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <typeparam name="type"></typeparam>
        /// <param name="total"></param>
        /// <param name="split"></param>
        /// <param name="take"></param>
        /// <param name="isAsc"></param>
        /// <param name="order"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        IQueryable<T> GetAll<type>(out int total,int split=1,int take=10,bool isAsc=true, Expression<Func<T, type>>? order = null, Expression<Func<T, bool>>? where = null);

    }
}
